package org.rency.crawler.fetch.repository.impl;

import javax.annotation.Resource;
import org.rency.crawler.domain.FetchExtension;
import org.rency.crawler.fetch.repository.FetchExtRepository;
import org.rency.crawler.fetch.repository.MetaResourceRepository;
import org.rency.crawler.integration.cache.FetchExtCacheClient;
import org.springframework.stereotype.Repository;

/**
 * 描述: ${TODO}<br>
 * 最近修改时间:2017/11/23 9:44<br>
 *
 * @author CaiyuRen
 * @version V1.0
 * @since 2017/11/23 9:44
 */
@Repository
public class FetchExtRepositoryImpl implements FetchExtRepository {

  @Resource
  private MetaResourceRepository metaResourceRepository;

  @Resource
  private FetchExtCacheClient fetchExtCacheClient;

  @Override
  public FetchExtension find(String fetchNo) {
    return fetchExtCacheClient.get(fetchNo);
  }

  @Override
  public boolean save(String fetchNo, FetchExtension extension) {
    fetchExtCacheClient.set(fetchNo,extension,metaResourceRepository.getFetchExtExpireTime());
    return true;
  }

  @Override
  public boolean update(String fetchNo, FetchExtension extension) {
    fetchExtCacheClient.set(fetchNo,extension,metaResourceRepository.getFetchExtExpireTime());
    return true;
  }

  @Override
  public long deleteAll() {
    return fetchExtCacheClient.removeAll();
  }
}
